import { ApiResult, PageResult } from '@/api';
import request from '@/utils/request';
import { SysOnlineUserParam } from './model';

enum API {
  ForceOffline = '/sysOnlineUser/forceOffline', //强制下线
  OnlineUserPage = '/sysOnlineUser/page' //分页获取在线用户
}

/**
 * 获取访问日志分页列表
 * @param params
 * @returns
 */
export const getOnlineUserPage = async (params?: SysOnlineUserParam) => {
  const res = await request.post<ApiResult<PageResult<any>>>(
    API.OnlineUserPage,
    params
  );
  if (res.data.code === 200) {
    return res.data.result;
  }
  return Promise.reject(new Error(res.data.message));
};

/**
 * 强制下线
 * @param params
 * @returns
 */
export const forceOffline = async (params?: any) => {
  const res = await request.post<ApiResult<any>>(API.ForceOffline, { params });
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
};
